package com.wuxq.serialport;

public class Utils {

    public static String byte2Hex2(byte[] bytes){
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            String value = String.format("%02X", b);
            sb.append(value);
        }
        return sb.toString();
    }

    public static String bytesToHex(byte[] bytes) {
        char[] hexArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        char[] hexChars = new char[bytes.length * 2];

        for(int j = 0; j < bytes.length; ++j) {
            int v = bytes[j] & 255;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 15];
        }

        return new String(hexChars);
    }
}
